package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcPartyMembers;
import com.ruoyi.system.service.IIcPartyMembersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党员Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@Controller
@RequestMapping("/system/icPartyMembers")
public class IcPartyMembersController extends BaseController
{
    private String prefix = "system/icPartyMembers";

    @Autowired
    private IIcPartyMembersService icPartyMembersService;

    @RequiresPermissions("system:icPartyMembers:view")
    @GetMapping()
    public String icPartyMembers()
    {
        return prefix + "/icPartyMembers";
    }

    /**
     * 查询党员列表
     */
    @RequiresPermissions("system:icPartyMembers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcPartyMembers icPartyMembers)
    {
        startPage();
        List<IcPartyMembers> list = icPartyMembersService.selectIcPartyMembersList(icPartyMembers);
        return getDataTable(list);
    }

    /**
     * 导出党员列表
     */
    @RequiresPermissions("system:icPartyMembers:export")
    @Log(title = "党员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcPartyMembers icPartyMembers)
    {
        List<IcPartyMembers> list = icPartyMembersService.selectIcPartyMembersList(icPartyMembers);
        ExcelUtil<IcPartyMembers> util = new ExcelUtil<IcPartyMembers>(IcPartyMembers.class);
        return util.exportExcel(list, "党员数据");
    }

    /**
     * 新增党员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存党员
     */
    @RequiresPermissions("system:icPartyMembers:add")
    @Log(title = "党员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcPartyMembers icPartyMembers)
    {
        return toAjax(icPartyMembersService.insertIcPartyMembers(icPartyMembers));
    }

    /**
     * 修改党员
     */
    @RequiresPermissions("system:icPartyMembers:edit")
    @GetMapping("/edit/{memberId}")
    public String edit(@PathVariable("memberId") Long memberId, ModelMap mmap)
    {
        IcPartyMembers icPartyMembers = icPartyMembersService.selectIcPartyMembersByMemberId(memberId);
        mmap.put("icPartyMembers", icPartyMembers);
        return prefix + "/edit";
    }

    /**
     * 修改保存党员
     */
    @RequiresPermissions("system:icPartyMembers:edit")
    @Log(title = "党员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcPartyMembers icPartyMembers)
    {
        return toAjax(icPartyMembersService.updateIcPartyMembers(icPartyMembers));
    }

    /**
     * 删除党员
     */
    @RequiresPermissions("system:icPartyMembers:remove")
    @Log(title = "党员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icPartyMembersService.deleteIcPartyMembersByMemberIds(ids));
    }
}
